import { Http } from "@/utils/request";
import { Toast } from "@/utils/toast";
import { delayTask } from "@/utils/timer";

const baseUrl = "/help_center";

export const home_api = (
  data: { package_name: string; platform: number },
  showError = true
) => {
  return Http.get<{ cate_list: any[]; items: any[] }>(
    `${baseUrl}/home`,
    data
  ).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const index_api = (
  data: { id: string; package_name: string; platform: number },
  showError = true
) => {
  return Http.get<{ items: any[] }>(`${baseUrl}/index`, data).catch(
    (error: Error) => {
      showError && delayTask(60, () => Toast.show(error.message));
      return Promise.reject(error);
    }
  );
};

export const detail_api = (data: { id: string }, showError = true) => {
  return Http.get<any>(`${baseUrl}/detail`, data).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};
